package com.sc.fs3.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 *  文本内容提取
 */
@Service
public class FileExtractService {

    private Logger log = LoggerFactory.getLogger(FileExtractService.class);

    public String extractContent(MultipartFile file){
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(file.getInputStream(),"utf-8"));
          //InputStream is = file.getInputStream();

            StringBuffer sb = new StringBuffer();
            String line;    //实际读取大小
            while((line = br.readLine())!=null){
                log.info("text -- : "+line);
                sb.append(line);
                sb.append("/r/n");
            }
            br.close();
            return sb.toString();   //返回文本内容
        } catch (IOException e) {
            log.error("文本提取异常");
            return "";
        }
    }
}
